home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / packer / xpk / xpkmashlib16.s < prev    next >
Text File  |  1995-03-09  |  7KB  |  297 lines

  1. ;XpkMASH library source (I)
  2.  
  3. ;at the end of this file is included xpkMASH16.library.S from RAM:
  4. ;select directory as you wish 
  5. ;
  6. ;Compiled with 1.3 includes
  7. ;
  8. ;sys inc
  9.     incdir    "df0:Include/"
  10. ;    incdir    "Include:"
  11.     include    "exec/types.i"
  12.     include    "exec/initializers.i"
  13.     include    "exec/libraries.i"
  14.     include    "exec/lists.i"
  15.     include    "exec/nodes.i"
  16.     include    "exec/resident.i"
  17.     include    "exec/exec_lib.i"
  18.     include    "exec/memory.i"
  19. ;xpk inc
  20.     include    "libraries/xpk.i"
  21.     include    "libraries/xpksub.i"
  22.  
  23. Pri        equ    -127
  24. Version        equ    1
  25. Revision    equ    16
  26. ResVersion    equ    1
  27.  
  28. ; global constants
  29.  
  30. PACKMEM        equ    0
  31.  
  32. UNPACKMEM    equ    0
  33.  
  34. PACKBUFFER    equ    $10000
  35. HASHBUFFER    equ    $20000
  36.  
  37. ; MASH librarystructure
  38.         STRUCTURE    XpkMash,LIB_SIZE
  39.         ULONG    xid_SysLib
  40.         ULONG    xid_SegList
  41.         STRUCT    xid_Reserved,32
  42.         LABEL    XpkMash_SIZEOF
  43.  
  44. ; usefull makros
  45.  
  46. CALLSYS MACRO
  47.         jsr    _LVO\1(a6)
  48.     ENDM
  49.  
  50. DummyEntry:    moveq    #-1,d0    ;Tell all fools trying to execute us
  51.         rts        ;that our execution failed. ;-)
  52.  
  53. Resident:    dc.w    RTC_MATCHWORD
  54.         dc.l    Resident
  55.         dc.l    ResEnd
  56.         dc.b    RTF_AUTOINIT
  57.         dc.b    ResVersion
  58.         dc.b    NT_LIBRARY
  59.         dc.b    Pri
  60.         dc.l    LibName
  61.         dc.l    IdString
  62.         dc.l    Init
  63.  
  64. LibName:    dc.b    'xpkMASH.library',0
  65. IdString:    dc.b    '$VER: xpkMASH.library V1.16',13,10,0
  66.         EVEN
  67.  
  68.  
  69. Init:        dc.l    XpkMash_SIZEOF
  70.         dc.l    FuncTable
  71.         dc.l    DataTable
  72.         dc.l    InitRoutine
  73.  
  74. ; --- sys
  75. FuncTable:    dc.l    Open
  76.         dc.l    Close
  77.         dc.l    Expunge
  78.         dc.l    Null
  79. ; --- xpksub
  80.         dc.l    PackerInfo
  81.         dc.l    PackChunk
  82.         dc.l    PackFree
  83.         dc.l    PackReset
  84.         dc.l    UnpackChunk
  85.         dc.l    UnpackFree
  86. ; --- omega
  87.         dc.l    -1
  88.  
  89.  
  90. DataTable:    INITBYTE    LH_TYPE,NT_LIBRARY
  91.         INITLONG    LN_NAME,LibName
  92.         INITBYTE    LIB_FLAGS,LIBF_SUMUSED+LIBF_CHANGED
  93.         INITWORD    LIB_VERSION,Version
  94.         INITWORD    LIB_REVISION,Revision
  95.         INITLONG    LIB_IDSTRING,IdString
  96.         dc.l    0
  97.  
  98.  
  99. InitRoutine:    move.l    a5,-(a7)
  100.         move.l    d0,a5
  101.         move.l    a6,xid_SysLib(a5)
  102.         move.l    a0,xid_SegList(a5)
  103.         move.l    (a7)+,a5
  104.         rts
  105.  
  106. ;--- sys entries
  107.  
  108. Open:        addq.w    #1,LIB_OPENCNT(a6)
  109.         bclr.b    #LIBB_DELEXP,LIB_FLAGS(a6)
  110.         move.l    a6,d0
  111. rts00:        rts
  112.  
  113.  
  114. Close:        moveq    #0,d0
  115.         subq.w    #1,LIB_OPENCNT(a6)
  116.         bne.s    rts00
  117.         btst.b    #LIBB_DELEXP,LIB_FLAGS(a6)
  118.         beq.s    rts00
  119.  
  120.     ;;; Fall through to Expunge and remove the lib from memory.
  121.  
  122. Expunge:    movem.l    d1-d2/a5-a6,-(a7)
  123.         move.l    a6,a5
  124.         move.l    xid_SysLib(a5),a6
  125.         tst.w    LIB_OPENCNT(a5)
  126.         beq.s    exp1
  127.         bset.b    #LIBB_DELEXP,LIB_FLAGS(a5)
  128.         moveq    #0,d0
  129.         bra.s    expEnd
  130.  
  131. exp1:        move.l    xid_SegList(a5),d2
  132.         move.l    a5,a1
  133.         CALLSYS    Remove
  134.         moveq    #0,d0
  135.         move.l    a5,a1
  136.         move.w    LIB_NEGSIZE(a5),d0
  137.         sub.l    d0,a1
  138.         add.w    LIB_POSSIZE(a5),d0
  139.         CALLSYS    FreeMem
  140.         move.l    d2,d0
  141. expEnd:        movem.l    (a7)+,d1-d2/a5-a6
  142.         rts
  143.  
  144. Null:        moveq    #0,d0
  145.         rts
  146.  
  147. ; --- End of sys stuff ---
  148.  
  149.  
  150. PACKCHUNKREGS    reg    d1-d7/a0-a6
  151. PackChunk:
  152.     movem.l PACKCHUNKREGS,-(a7)
  153.     move.l    a6,a5            ; lib base
  154.     move.l    a0,a4            ; xparams
  155.     move.l    xid_SysLib(a5),a6
  156.  
  157. AllocPackMem:
  158.     move.l    #PACKBUFFER,d0
  159.     move.l    d0,d3
  160.     moveq    #MEMF_PUBLIC,d1
  161.     CALLSYS AllocMem
  162.     tst.l    d0
  163.     beq.b    NoMemoryMain
  164.     move.l    d0,a2
  165.  
  166. packMemOK:
  167.     movem.l    d3/a2,-(a7)
  168.     move.l    #HASHBUFFER,d3        ;$20000 bytes needed
  169.     moveq    #8,d5            ;16 bits hash
  170. .next_try
  171.     move.l    d3,d0
  172.     moveq    #MEMF_PUBLIC,d1
  173.     CALLSYS    AllocMem
  174.     tst.l    d0
  175.     bne.b    .memok
  176.     lsr.l    #1,d3            ;divide memory needed for hash func
  177.     lsr.w    #1,d5
  178.     cmp.w    #1,d5
  179.     bcc.b    .next_try            ;mim. 9 bits
  180.     bra.b    NoMemoryHash
  181. .memok    move.l    d0,a3
  182.     movem.l    d3/a3,-(a7)        ;d5:=number of bits for hash func
  183.     move.l    xsp_InBuf(a4),a0        ;a0:=InBuf
  184.     move.l    xsp_OutBuf(a4),a1       ;a1:=OutBuf
  185.     move.l    xsp_InLen(a4),d7    ;d7:=InLen
  186.     lea    -50(a1,d7.l),a5
  187.     move.l    a5,xsp_Sub+2*4(a4)    ;xsp_Sub+8:=end of chunk
  188.     move.l    xsp_Mode(a4),d1
  189.     divs    #10,d1
  190.     moveq    #1,d2
  191.     asl.w    d1,d2
  192.     move.l    d2,xsp_Sub+3*4(a4)    ;xsp_Sub+12:=deep counter
  193.                     ;a2:=Hash buffer
  194.     bsr.w    Pack_It            ;Call the compressor.
  195.     move.l    d0,xsp_OutLen(a4)    ;Fill in Final output length XpkSubParams
  196.  
  197.     movem.l    (a7)+,d0/a1        ;Free allocated buffers
  198.     CALLSYS    FreeMem
  199.  
  200.     movem.l    (a7)+,d0/a1
  201.     CALLSYS    FreeMem
  202.  
  203.     tst.l    xsp_OutLen(a4)
  204.     bne.s    Nooverrun
  205.     moveq.l #XPKERR_EXPANSION,d0
  206.     bra.s    endPackChunk
  207. NoMemoryHash:                    ;Something goes wrong
  208.     movem.l    (a7)+,d0/a1            ;free allocated buffers
  209.     CALLSYS    FreeMem
  210. NoMemoryMain:
  211.     moveq    #XPKERR_NOMEM,d0
  212.     bra.s    endPackChunk    
  213. Nooverrun:
  214.     moveq    #XPKERR_OK,d0
  215. endPackChunk:
  216.     movem.l (sp)+,PACKCHUNKREGS
  217.     rts
  218.  
  219. PackFree:
  220. UnpackFree:
  221. PackReset:    moveq    #XPKERR_OK,d0
  222.         rts
  223.  
  224. UnpackChunk:    move.l    a1,-(sp)
  225.         move.l    xsp_OutBuf(a0),a1
  226.         move.l    a1,d4
  227.         add.l    xsp_OutLen(a0),d4
  228.         move.l    xsp_InBuf(a0),a0
  229.         bsr.w    UnPack_It
  230.         move.l    (sp)+,a1
  231.         moveq    #XPKERR_OK,d0
  232.         rts
  233.  
  234. PackerInfo:    move.l    a0,d0
  235.         lea    MashInfo(pc),a0
  236.         exg.l    a0,d0
  237.         rts
  238.  
  239.  
  240.  
  241. ; --- Static Data --------
  242. MashInfo:
  243.  dc.w    1        ;xi_XpkInfoVersion:Version number of this structure
  244.  dc.w    Version     ;xi_LibVersion     : The version of this sublibrary
  245.  dc.w    2        ;xi_MasterVersion: The required master lib version
  246.  dc.w    0        ;xi_ModesVersion : Longword align
  247.  dc.l    MashName    ;xi_Name     : Brief name of the packer
  248.  dc.l    LongName    ;xi_LongName     : Full name of the packer
  249.  dc.l    Description    ;xi_Description  : One line description of packer
  250.  dc.b    'MASH'          ;xi_ID           : ID the packer goes by (XPK format)
  251.             ;xi_Flags     : Defined below
  252.  dc.l    XPKIF_PK_CHUNK+XPKIF_UP_CHUNK+XPKIF_MODES
  253.  dc.l    $f0000        ;xi_MaxPkInChunk : Max input chunk size for packing
  254.  dc.l    80        ;xi_MinPkInChunk : Min input chunk size for packing
  255.  dc.l    $10000        ;xi_DefPkInChunk : Default packing chunk size
  256.  dc.l    PackMsg     ;xi_PackMsg     : Packing message, present tense
  257.  dc.l    UnpackMsg    ;xi_UnpackMsg     : Unpacking message, present tense
  258.  dc.l    PackedMsg    ;xi_PackedMsg     : Packing message, past tense
  259.  dc.l    UnpackedMsg    ;xi_UnpackedMsg  : Unpacking message, past tense
  260.  dc.w    100        ;xi_DefMode     : Default mode number
  261.  dc.w    0        ;xi_Pad      : for future use
  262.  dc.l    Modes        ;xi_Modes     : Array of compression modes
  263.  dc.l    0,0,0,0,0,0    ;xi_Reserved,6*4 : Future expansion - set to zero
  264.         ;LABEL    ;xi_SIZEOF     : Size of the *first* part only
  265.  
  266. MashName:    dc.b    'Mashiner',0
  267. LongName:    dc.b    'MASH V1.16, another LZ77-family',0
  268. Description:    dc.b    'WindowSize: 32KB, 2 mixed streams  '
  269.         dc.b    'Dynamic Buffer Allocation,  Nice CF',0
  270. PackMsg:    dc.b    'Mashing',0
  271. PackedMsg:    dc.b    'Mashed',0
  272. UnpackMsg:    dc.b    'UnMashing',0
  273. UnpackedMsg:    dc.b    'UnMashed',0
  274.  
  275.     EVEN
  276.  
  277. Modes:
  278.  dc.l    0        ;xm_Next      : Chain to next descriptor for ModeDesc list
  279.  dc.l    100        ;xm_Upto      : Maximum efficiency handled by this mode.
  280.             ;xm_Flags      : Defined below
  281.  dc.l    0        ;XPKMF_A3000SPEED
  282.  dc.l    PACKMEM     ;xm_PackMemory      : Extra memory required during packing
  283.  dc.l    UNPACKMEM    ;xm_UnpackMemory  : Extra memory during unpacking
  284.  dc.l    18        ;xm_PackSpeed      : Approx packing speed in K per second
  285.  dc.l    300        ;xm_UnpackSpeed   : Approx unpacking speed in K per second
  286.  dc.w    480        ;xm_Ratio      : CF in 0.1% for AmigaVision executable
  287.  dc.w    0        ;xm_ChunkSize      : Desired chunk size in K (!!) for this mode
  288.  dc.b    ' -->    '      ;xm_Description,10:8 character mode description
  289.  dc.l    0
  290.  
  291.         ;LABEL    ;xm_SIZEOF
  292.  
  293.     incdir    'ram:'
  294.     include    'xpkMASH16.library.S'
  295. ResEnd:
  296.     
  297.